package com.wthink.newMain.settings.update

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.wthink.hzgj.R
import com.wthink.hzgj.databinding.FragmentUpdateFixBinding
import com.wthink.newMain.settings.update.viewmodel.UpdateFixViewmodel

class UpdateFixFragment : Fragment(){
    private val viewModel by viewModels<UpdateFixViewmodel>()

    private lateinit var binding: FragmentUpdateFixBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(
            inflater,
            R.layout.fragment_update_fix,
            container,
            false
        )
        binding.viewModel = viewModel
        binding.lifecycleOwner = this
        return binding.root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel.start()

        binding.btnFactory.setOnClickListener {
            viewModel.update("restore_dev")
        }
        binding.btnRestart.setOnClickListener {
            viewModel.update("reboot_dev")
        }
        binding.btnUpdateDevice.setOnClickListener {
            viewModel.update("upgrade_bus")
        }
        binding.btnUpdateScreen.setOnClickListener {
            viewModel.update("upgrade_screen")
        }
    }
}